package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrOutcupDifferenceAnalysisMapper;
import com.yunhai.device.service.OrrOutcupDifferenceAnalysisService;
import com.yunhai.model.entity.orr.OrrOutcupDifferenceAnalysisEntity;
import com.yunhai.model.vo.orr.OrrOutcupDifferenceAnalysisQuery;
import com.yunhai.model.vo.orr.OrrOutcupDifferenceAnalysisVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrOutcupDifferenceAnalysisServiceImpl implements OrrOutcupDifferenceAnalysisService {

    @Resource
    private OrrOutcupDifferenceAnalysisMapper orrOutcupDifferenceAnalysisMapper;

    /**
     * 获取 OrrOutcupDifferenceAnalysis 分页列表
     */
    @Transactional
    public IPage getOrrOutcupDifferenceAnalysisPagination(PaginationVo paginationVo, OrrOutcupDifferenceAnalysisQuery orrOutcupDifferenceAnalysisQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrOutcupDifferenceAnalysisEntity> lqs = new LambdaQueryWrapper();
        orrOutcupDifferenceAnalysisMapper.selectPage(page, lqs);

        List<OrrOutcupDifferenceAnalysisEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrOutcupDifferenceAnalysis 所有数据
     *
     */
    @Transactional
    public List<OrrOutcupDifferenceAnalysisEntity> getOrrOutcupDifferenceAnalysisAllList( OrrOutcupDifferenceAnalysisQuery orrOutcupDifferenceAnalysisQuery ) throws Exception {

        LambdaQueryWrapper<OrrOutcupDifferenceAnalysisEntity> lqs = new LambdaQueryWrapper();
        List<OrrOutcupDifferenceAnalysisEntity> list = orrOutcupDifferenceAnalysisMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrOutcupDifferenceAnalysis 详情
     */
    @Transactional
    public OrrOutcupDifferenceAnalysisEntity getOrrOutcupDifferenceAnalysisDetail( Long id) throws Exception {

        OrrOutcupDifferenceAnalysisEntity orrOutcupDifferenceAnalysisEntity = orrOutcupDifferenceAnalysisMapper.selectById(id);
        return orrOutcupDifferenceAnalysisEntity;
    }


    /**
     * 新增 OrrOutcupDifferenceAnalysis
     * */
    @Transactional
    public void addOrrOutcupDifferenceAnalysis(OrrOutcupDifferenceAnalysisVo orrOutcupDifferenceAnalysisVo) throws Exception {

        OrrOutcupDifferenceAnalysisEntity orrOutcupDifferenceAnalysisEntity = new OrrOutcupDifferenceAnalysisEntity();
        ReflectionCopy.copyProperties( orrOutcupDifferenceAnalysisEntity, orrOutcupDifferenceAnalysisVo );
        orrOutcupDifferenceAnalysisMapper.insert(orrOutcupDifferenceAnalysisEntity);
        return;
    }


    /**
     * 更新 OrrOutcupDifferenceAnalysis
     * */
    @Transactional
    public void updateOrrOutcupDifferenceAnalysis( OrrOutcupDifferenceAnalysisVo orrOutcupDifferenceAnalysisVo) throws Exception {

        if( orrOutcupDifferenceAnalysisVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrOutcupDifferenceAnalysisEntity orrOutcupDifferenceAnalysisEntity = new OrrOutcupDifferenceAnalysisEntity();
        ReflectionCopy.copyProperties( orrOutcupDifferenceAnalysisEntity, orrOutcupDifferenceAnalysisVo );
        orrOutcupDifferenceAnalysisMapper.updateById(orrOutcupDifferenceAnalysisEntity);
        return;
    }

    /**
     * 删除 OrrOutcupDifferenceAnalysis
     * */
    @Transactional
    public void batchRemoveOrrOutcupDifferenceAnalysis( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrOutcupDifferenceAnalysisMapper.deleteBatchIds(ids);
    }

}